package com.ijiuchuang.jc_localization.presenter.tools;

import android.app.ProgressDialog;
import android.content.Context;

import com.ijiuchuang.jc_localization.bean.bmob.signin.Student;
import com.ijiuchuang.jc_localization.contract.tools.ToolsSignInContract;
import com.ijiuchuang.jc_localization.model.tools.ToolsSignInModel;
import com.ijiuchuang.jc_localization.tools.utils.Log;

import rx.Subscriber;

/**
 * Created by Veev on 2016/7/15
 *
 * @link 384506557@qq.com
 */
public class ToolsSignInPresenter implements ToolsSignInContract.Presenter {

    private Context mContext;
    private ToolsSignInContract.View mView;
    private ToolsSignInContract.Model mModel;

    private ProgressDialog dialog;

    public ToolsSignInPresenter(Context mContext, ToolsSignInContract.View mView) {
        this.mContext = mContext;
        this.mView = mView;
        this.mModel = new ToolsSignInModel();

        mView.setPresenter(this);
    }

    @Override
    public void start() {
        // start here
        dialog = new ProgressDialog(mContext);
        mView.showProgressDialog(dialog);
        mModel.checkStudent(mContext, new Subscriber<Student>() {
            @Override
            public void onCompleted() {
                Log.i("Completed on ToolsSignInPresenter start: no student");
                mView.dismissProgressDialog(dialog);
            }

            @Override
            public void onError(Throwable e) {
                Log.i("Error on ToolsSignInPresenter start: " + e.toString());
                mView.dismissProgressDialog(dialog);
            }

            @Override
            public void onNext(Student student) {
                Log.i("Next on ToolsSignInPresenter start: " + student);
                mModel.setCurrentStudent(student);
            }
        });

        //mView.showSetStudentDialog();
    }
}